﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using DatabaseHelper;
using System.IO;
using SDK10kWrapper;
using System.Configuration;
using RS232;
using UI.Online.SubForms;

namespace UI.Online
{
    public partial class frmOnlineUI2
    {
        private void tmrAutoStop_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (bIsRecording)
            {
                // Calculate the recorded duration
                TimeSpan ts = DateTime.Now.Subtract(t_start);
                if (TimeSpan.Compare(ts, MaxRecordTime) < 0)
                {
                    // Format the timespan in hh:mm:ss
                    txtRecordedTime.Text = String.Format("{0:00}:{1:00}:{2:00}", ts.Hours, ts.Minutes, ts.Seconds);
                }
                else
                {
                    StopRecord();
                    StartRecord();
                }
            }
        }

        private void cbbProject_SelectedIndexChanged(object sender, EventArgs e)
        {
            DBHelper dh = new DBHelper();
            string str = cbbProject.Text;
            dh.Query = "SELECT * FROM Projects WHERE ProjectName = '" + str + "'";
            DataTable dt = dh.Fill();
            currProjectID = int.Parse(dt.Rows[0]["ProjectID"].ToString());
            currProjectLocation = dt.Rows[0]["Location"].ToString();
            currProjectName = str;
            LoadPipeline();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            DBHelper dh = new DBHelper();
            // Get data
            PData pdt = new PData();
            pdt = DataNow;

            // Add start of survey event
            PEvent ss = new PEvent();
            ss = pdt.ToPEvent();
            ss.EventTime = DateTime.Now;
            ss.Description = txtDescription.Text;
            ss.Comment = txtComment.Text;
            ss.GeneralComment = txtGeneralComment.Text;
            tlvProjectEvent.AddEvent(ss, currRecordID.ToString());
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            tlvProjectEvent.DeleteEvents();
        }

        private void cbMute_CheckedChanged(object sender, EventArgs e)
        {
            if (cbMute.Checked)
            {
                cam1.SoundOFF();
            }
            else
            {
                cam1.SoundON();
            }
        }

        private void cbbPipeline_SelectedIndexChanged(object sender, EventArgs e)
        {
            string str = cbbPipeline.Text;
            DBHelper dh = new DBHelper();
            dh.Query = "SELECT * FROM Pipelines WHERE PipelineName = '" + str + "'";
            DataTable dt = dh.Fill();
            currPipelineID = int.Parse(dt.Rows[0]["PipelineID"].ToString());
            currPipelineName = str;
        }
    }
}
